package domain

import (
	"github.com/casdoor/casdoor-go-sdk/auth"
	"gluenet/modules/manager/server/domain/aggregate"
	"gluenet/modules/manager/server/infra/prepare"
)

func init() {
	prepare.RegisterService(func() {
		login := NewLogin()
		prepare.InjectDependency(func() *Auth {
			return login
		})
	})
}

func NewLogin() *Auth {
	login := Auth{}
	prepare.FetchDependency(&login.UserLogin)
	return &login
}

type Auth struct {
	UserLogin *aggregate.UserAuth
}

func (r *Auth) Login(code string, state string) (token string, err error) {
	return r.UserLogin.Login(code, state)
}

func (r *Auth) Auth(token string) (*auth.Claims, error) {
	return r.UserLogin.Auth(token)
}
